package 动态规划9月;
// https://leetcode-cn.com/problems/length-of-last-word/
public class 字符串58最后一个单词的长度0921 {
    //me
    class Solution {
        public int lengthOfLastWord(String s) {
            String newS=s.trim();
            String newSarr[]=newS.split(" ");
            return newSarr[newSarr.length-1].length();
        }
    }
    //三叶姐
    class Solution1 {
        public int lengthOfLastWord(String s) {
            int n = s.length();
            int j = n - 1;
            while (j >= 0 && s.charAt(j) == ' ') j--;
            int i = j;
            while (i >= 0 && s.charAt(i) != ' ') i--;
            return j - i;
        }
    }

}
